package cn.lyjuan.android.demofive;

import android.app.Activity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;

import cn.lyjuan.android.demofive.chapter12.app_12_2_5_1.TumblerActivity;
import cn.lyjuan.android.demofive.system.particular.TouchEventActivity;
import cn.lyjuan.android.demofive.ui.translate.ScaleUpActivity;
import cn.lyjuan.android.demofive.ui.translate.SceneStartActivity;
import cn.lyjuan.android.demofive.ui.translate.StartActivity;
import cn.lyjuan.android.demofive.ui.translate.ThumbnailActivity;
import cn.lyjuan.android.demofive.ui.component.auto_complete_textview.AutoCompleteTextView;
import cn.lyjuan.android.demofive.ui.component.date_picker.DatePickerActivity;
import cn.lyjuan.android.demofive.ui.component.date_picker_dialog.DatePickerDialogActivity;
import cn.lyjuan.android.demofive.ui.component.spinner.SpinnerActivity;
import cn.lyjuan.android.demofive.ui.component.time_picker.TimePickerActivity;
import cn.lyjuan.android.demofive.ui.component.time_picker_dialog.TimePickerDialogActivity;
import cn.lyjuan.android.demofive.ui.cut_animation.CutAnimationActivity;
import cn.lyjuan.android.demofive.ui.layout.grid_view.GridViewActivity;
import cn.lyjuan.android.demofive.ui.slide.flipper.FlipperActivity;
import cn.lyjuan.android.demofive.ui.slide.flipper.FlipperNavActivity;
import cn.lyjuan.android.demofive.ui.slide.load.SlideUpLoadActivity;
import cn.lyjuan.android.demofive.ui.slide.load.SwipeRefreshActivity;
import cn.lyjuan.android.demofive.ui.slide.scroll.DrawerActivity;
import cn.lyjuan.android.demofive.ui.slide.scroll.FrameLayoutActivity;
import cn.lyjuan.android.demofive.ui.slide.scroll.OneLayoutActivity;
import cn.lyjuan.android.demofive.ui.slide.viewpage.ViewPageActivity;
import cn.lyjuan.android.demofive.ui.slide.viewpage.ViewPagerIndexActivity;
import cn.lyjuan.android.demofive.ui.tab.tabhost.TabHostActivity;
import cn.lyjuan.android.demofive.ui.webview.WebViewActivity;

/**
 * Created by chad on 2016/3/27.
 */
public class Res
{
    /**
     * 首页信息
     */
    private static TagInfo INDEX = new TagInfo("Index");

    static
    {
        INDEX.add(chp12());
        INDEX.add(ui());
        INDEX.add(system());
    }

    public static TagInfo getIndex()
    {
        // 防止修改
        TagInfo temp = new TagInfo(INDEX.name);
        temp.add(INDEX.items.toArray(new IItem[INDEX.items.size()]));
        return temp;
    }

    public static IItem system()
    {
        IItem particular = new TagInfo("Particular")
                .add("Touch父子View机制", TouchEventActivity.class);

        IItem system = new TagInfo("System").add(particular);

        return system;
    }

    public static IItem chp12()
    {
        // Chapter 12
        IItem chp12 = new TagInfo("Chapter-12")
                .add("12.2.5-1 不倒翁", TumblerActivity.class);
        return chp12;
    }

    public static IItem ui()
    {
        // UI
        IItem ui = new TagInfo("UI");
        // "布局"
        IItem layout = new TagInfo("Layout")
                .add("GridView", GridViewActivity.class);
        // "组件",
        IItem component = new TagInfo("Component")
                .add("AutoCompleteTextView", AutoCompleteTextView.class)
                .add("DatePickerActivity", DatePickerActivity.class)
                .add("DatePickerDialog", DatePickerDialogActivity.class)
                .add("TimePicker", TimePickerActivity.class)
                .add("TimePickerDialog", TimePickerDialogActivity.class)
                .add("Spinner", SpinnerActivity.class);
        //"tab"
        IItem tab = new TagInfo("Tab")
                .add("继承TabHost", TabHostActivity.class)
                .add("单Layout的TabHost", cn.lyjuan.android.demofive.ui.tab.tabhost2.TabHostActivity.class)
                .add("独立Layout的TabHost", cn.lyjuan.android.demofive.ui.tab.tabhost3.TabHostActivity.class)
                .add("底部Tab", cn.lyjuan.android.demofive.ui.tab.tabhost4.TabHostActivity.class);
        // "滑动"
        IItem slide = new TagInfo("Slide")
                .add("Flipper滑动", FlipperActivity.class)
                .add("ViewPager滑动的Tab", ViewPageActivity.class)
                .add("索引圆点的ViewPager", ViewPagerIndexActivity.class)
                .add("渐隐导航按钮的Flipper", FlipperNavActivity.class)
                .add("下拉刷新SwipeRefresh", SwipeRefreshActivity.class)
                .add("上滑加载ListView&OnScorllListener", SlideUpLoadActivity.class);
        // "滑动菜单"
        IItem slideMenu = new TagInfo("SlideMenu")
                .add("覆盖的Fragment", FrameLayoutActivity.class)
                .add("Navigation DrawerLayout", DrawerActivity.class)
                .add("菜单溢出到左边隐藏", OneLayoutActivity.class);
        // "Activity切换动画"
        IItem swith = new TagInfo("SwithActivity")
                .add("Acitivty切换效果", CutAnimationActivity.class);
        // "WebView及JS交互"
        IItem webViewJs = new ActivityInfo("WebViewWithJs", WebViewActivity.class);

        ui.add(layout)
                .add(component)
                .add(tab)
                .add(slide)
                .add(slideMenu)
                .add(swith)
                .add(webViewJs)
                .add(new TagInfo("TranslateAnimation")
                        .add(new ActivityInfo("自定义动画", StartActivity.class))
                        .add(new ActivityInfo("向上缩放", ScaleUpActivity.class))
                        .add(new ActivityInfo("缩放图片", ThumbnailActivity.class))
                        .add(new ActivityInfo("场景互动", SceneStartActivity.class))
                );

        return ui;
    }

    /**
     * {@link TagInfo}或{@Link ActivityInfo}统一接口
     */
    public static class IItem implements Serializable
    {
        protected String name;

        public String getName()
        {
            return this.name;
        }

        public IItem add(IItem item)
        {
            return this;
        }

        public IItem add(IItem... items)
        {
            return this;
        }

        public IItem add(String name)
        {
            return this;
        }

        public IItem add(String name, Class<? extends Activity> cls)
        {
            return this;
        }
    }

    /**
     * 表示标签
     */
    public static class TagInfo extends IItem
    {
        public ArrayList<IItem> items = new ArrayList<>(4);

        public TagInfo(String name)
        {
            this.name = name;
        }

        public IItem add(IItem item)
        {
            items.add(item);
            return this;
        }

        public IItem add(IItem... items)
        {
            if (null != items && items.length > 0)
                this.items.addAll(Arrays.asList(items));

            return this;
        }

        /**
         * add {@link ActivityInfo}
         *
         * @param name
         * @param cls
         * @return
         */
        public IItem add(String name, Class<? extends Activity> cls)
        {
            IItem item = new ActivityInfo(name, cls);
            this.add(item);
            return this;
        }

        /**
         * add {@link TagInfo}
         *
         * @param name
         * @return
         */
        public IItem add(String name)
        {
            IItem item = new TagInfo(name);
            this.add(item);
            return this;
        }
    }

    /**
     * 表示Activity
     */
    public static class ActivityInfo extends IItem
    {
        public Class<? extends Activity> cls;

        public ActivityInfo(String name, Class<? extends Activity> cls)
        {
            this.name = name;
            this.cls = cls;
        }
    }
}
